/*
 * File		:bsp_uart.c
 * This file is usart driver
 * 
 *
 * change Logs:
 * Date		Author		Notes
 * 2009-01-05	guanjingxin	first implementation
 *
 *
 */


/*
*********************************************************************************************************
*                                            INCLUDE FILES
*********************************************************************************************************
*/

#include  <cpu_core.h>
#include "fsl_debug_console.h"
#include "bsp_uart.h"

/* Get debug console frequency. */
CPU_INT32U BSP_DebugConsoleSrcFreq(void)
{
    CPU_INT32U freq;

    /* To make it simple, we assume default PLL and divider settings, and the only variable
       from application is use PLL3 source or OSC source */
    if (CLOCK_GetMux(kCLOCK_UartMux) == 0) /* PLL3 div6 80M */
    {
        freq = (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
    }
    else
    {
        freq = CLOCK_GetOscFreq() / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U);
    }

    return freq;
} 
 
/* Initialize debug console. */
void BSP_InitDebugConsole(void)
{
    CPU_INT32U uartClkSrcFreq = BSP_DebugConsoleSrcFreq();

    DbgConsole_Init(BSP_DEBUG_UART_BASEADDR, BSP_DEBUG_UART_BAUDRATE, BSP_DEBUG_UART_TYPE, uartClkSrcFreq);
}

 
